package com.ycj.design.create.singleton;

/**
 * 双重检查(推荐使用)
 * 进行双重检查，两次if判断，在使用方法的时候判断，在线程同步后再一次判断，保证了线程安全，
 * 优点:线程安全，延迟加载，效率较高
 * @author chuanjieyang
 * @date Nov 20, 2018 11:37:25 AM
 */
public class SingletonPatternSex {
    private volatile static SingletonPatternSex instance;

    private SingletonPatternSex(){}

    public static SingletonPatternSex getInstance(){
        if(instance==null){
            synchronized (SingletonPatternSex.class){
                if(instance==null)instance=new SingletonPatternSex();
            }
        }

        return instance;
    }
}
